﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WithdrawCash.aspx.cs" Inherits="YY.Web.MyAgent.financial_information.WithdrawCash" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>提现</title>
    <link type="text/css" href="/css/finance.css" rel="stylesheet" />
    <link type="text/css" href="/css/common.css" rel="stylesheet" />
    <script src="/jQuery/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
        $(function () {
            LoadMyBankCard();
            //提交申请
            $("#btn_apply").click(function () {
                var valattr = $("#div_ErrorInfor").css("display");
                var BankCardNo = $(".bankselect").val().toString().split('_')[0];
                var BankCardId = $(".bankselect").val().toString().split('_')[1];
                var ArrivalAccountDateType = $('input[name="RadioGroup1"]:checked ').val();
                var cash = $("#txt_Money").val();
                var code = $("#txt_smscode").val();
                var password = $("#txt_password").val();
                if (!BankCardNo) {
                    $("#div_ErrorInfor").html("您还没有添加银行卡,请添加");
                    $("#div_ErrorInfor").show();
                }
                else if (cash == "") {
                    $("#div_ErrorInfor").html("请输入提现金额");
                    $("#div_ErrorInfor").show();
                }
                else if (!MoneyConpare()) {

                }
                else if (password == "") {
                    $("#div_ErrorInfor").html("请输入交易密码");
                    $("#div_ErrorInfor").show();
                }
                else {
                    //验证交易密码
                    $.post("FinanceHandler.ashx?action=CheckTradePassword", { "tradepassword": password }, function (data, status) {
                        if (status == "success") {
                            if (data == "1") {
                                $("#div_ErrorInfor").hide();
                                //验证短信验证码
                                if (code == "") {
                                    $("#div_ErrorInfor").hide();
                                }
                                else {
                                    $.post("FinanceHandler.ashx?action=CheckCodeToWithdraw", { "smscode": code }, function (data, status) {
                                        if (data == "1") {
                                            $("#div_ErrorInfor").hide();
                                            $.post("FinanceHandler.ashx?action=ApplyWithdrawCash", { "BankCardId": BankCardId, "BankCardNo": BankCardNo, "ArrivalAccountDateType": ArrivalAccountDateType, "cash": cash }, function (data, status) {
                                                if (status == "success") {
                                                    if (data > 0) {
                                                        window.location.href = "WithdrawalSuccess.aspx";
                                                    }
                                                    else {
                                                        alert("提交失败，请重新操作!");
                                                    }
                                                }
                                            });
                                        }
                                        else {
                                            $("#div_ErrorInfor").html("短信验证码不正确或已过期");
                                            $("#div_ErrorInfor").show();
                                        }
                                    });
                                }
                            }
                            else if (data == "0") {
                                $("#div_ErrorInfor").html("交易密码填写错误，请重新填写");
                                $("#div_ErrorInfor").show();
                            }
                            else if (data == "-1") {
                                if (confirm("您的交易密码尚未注册,请去完善！")) {
                                    window.location.href = "/MyInfo/SetPayPassword/SettingPaypassword1.aspx";
                                }
                            }
                        }
                    });
                }
            });
        });

        //加载我绑定的银行卡
        function LoadMyBankCard() {
            $.post("FinanceHandler.ashx?action=BankAccount", function (data, status) {
                if (status == "success") {
                    var infor = JSON.parse(data);
                    var htmlstring = "";
                    for (var i = 0; i < infor.length; i++) {
                        if (infor[i].IsDefaultCard == 1) {
                            //有默认银行的时候 将默认银行的银行卡号默认第一个
                            htmlstring += "<option value='" + infor[i].BankCardNo2 + "_" + infor[i].ID + "' selected='selected'>" + infor[i].BankName + "</option>";
                            var newbankcard = infor[i].BankCardNo2.toString().substring(0, 6) + "***" + infor[i].BankCardNo2.toString().substring(infor[i].BankCardNo2.toString().length - 4, infor[i].BankCardNo2.toString().length);
                            $("#txt_BankCardId").val(newbankcard);
                        }
                        else {
                            //没有默认银行的时候 将第一个银行默认第一个
                            if (i == 0) {

                                htmlstring += "<option value='" + infor[i].BankCardNo2 + "_" + infor[i].ID + "' selected='selected' >" + infor[i].BankName + "</option>";
                                var newbanknum = infor[i].BankCardNo2.toString().substring(0, 6) + "***" + infor[i].BankCardNo2.toString().substring(infor[i].BankCardNo2.toString().length - 4, infor[i].BankCardNo2.toString().length);
                                $("#txt_BankCardId").val(newbanknum);
                            }
                            else {
                                htmlstring += "<option value='" + infor[i].BankCardNo2 + "' >" + infor[i].BankName + "</option>";
                            }
                        }
                    }
                    $(".bankselect").html(htmlstring);
                }
            });
        }

        //取款验证
        function MoneyConpare() {
            var infor = "";
            var money = $("#txt_Money").val();
            var hidden_money = $("#HiddenMoney").val();
            if (money == "") {
                $("#div_ErrorInfor").html("请输入提现金额");
                $("#div_ErrorInfor").show();
                return false;
            }
            else if (money > 50000) {
                $("#div_ErrorInfor").html("单笔提现最高金额为50000元");
                $("#div_ErrorInfor").show();
                return false;
            }
            else {
                var ArrivalAccountDateType = $('input[name="RadioGroup1"]:checked ').val();
                var sxf = "";
                if (ArrivalAccountDateType == "1") {
                    sxf = "5";
                }
                else {
                    sxf = "10";
                }
                if (parseInt(money) + parseInt(sxf) > parseInt(hidden_money)) {
                    $("#div_ErrorInfor").html("余额不足,无法取出");
                    $("#div_ErrorInfor").show();
                    return false;
                }
                else {
                    $("#true_money").html("您实际到账" + money + "元，扣除手续费" + sxf + "元。");
                    $("#true_money").show();
                    $("#div_ErrorInfor").hide();
                    return true;
                }
            }
        }

        //交易密码确认
        function CheckTradePassword() {
            var tradepassword = $("#txt_password").val();
            if (tradepassword == "") {
                $("#div_ErrorInfor").hide();
            }
            else {
                $.post("FinanceHandler.ashx?action=CheckTradePassword", { "tradepassword": tradepassword }, function (data, status) {
                    if (status == "success") {
                        if (data == "1") {
                            $("#div_ErrorInfor").hide();
                        }
                        else if (data == "0") {
                            $("#div_ErrorInfor").html("交易密码填写错误，请重新填写");
                            $("#div_ErrorInfor").show();
                        }
                        else if (data == "-1") {
                            if (confirm("您的交易密码尚未注册,请去完善！")) {
                                window.location.href = "/MyInfo/SetPayPassword/SettingPaypassword1.aspx";
                            }
                        }
                    }
                });
            }
        }

        function Countdown() {
            //倒计时
            var timevalue = $(".yzm-notclick").html();
            var length = timevalue.length;
            var valuenumber = "";
            if (length == 8) {
                //两位数字
                valuenumber = timevalue.substring(0, 2);
            }
            else {
                //一位数字
                valuenumber = timevalue.substring(0, 1);
            }
            valuenumber = valuenumber - 1;
            var fontvalue = valuenumber + "s后重新获取";
            if (valuenumber < 0) {
                clearInterval(SecondCode);
                $(".yzm-notclick").hide();
                $(".yzm-click").show();
            }
            else {
                $(".yzm-notclick").html(fontvalue);
            }
        }

        var SecondCode = "";

        //发送短信
        function SendSMSCode() {
            var valattr = $("#div_ErrorInfor").css("display");
            var BankCardNo = $(".bankselect").val();
            var ArrivalAccountDateType = $('input[name="RadioGroup1"]:checked ').val();
            var cash = $("#txt_Money").val();
            var code = $("#txt_smscode").val();
            var password = $("#txt_password").val();
            if (cash == "") {
                $("#div_ErrorInfor").html("请输入提现金额");
                $("#div_ErrorInfor").show();
            }
            else if (!MoneyConpare()) {

            }
            else if (password == "") {
                $("#div_ErrorInfor").html("请输入交易密码");
                $("#div_ErrorInfor").show();
            }
            else {
                //验证交易密码
                $.post("FinanceHandler.ashx?action=CheckTradePassword", { "tradepassword": password }, function (data, status) {
                    if (status == "success") {
                        if (data == "1") {
                            $("#div_ErrorInfor").hide();
                            //验证短信验证码
                            $(".yzm-notclick").html("60s后重新获取");
                            $(".yzm-notclick").show();
                            $(".yzm-click").hide();
                            SecondCode = window.setInterval("Countdown()", 1000);
                            $.post("FinanceHandler.ashx?action=SendSMSCode", function (data, status) {
                                if (status == "success") {
                                    var arr = new Array();
                                    arr = data.split("_");
                                    var code = arr[0];
                                    var status = arr[1];
                                    var phonenumber = arr[2];
                                    if (status != "success") {
                                        $("#div_ErrorInfor").html("获取短信验证码失败，请重新获取");
                                        $("#div_ErrorInfor").show();
                                    }
                                    else {
                                        $("#div_ErrorInfor").html("已向" + phonenumber + "发送验证码,请查看");
                                        $("#div_ErrorInfor").show();
                                    }
                                }
                            });
                        }
                        else if (data == "0") {
                            $("#div_ErrorInfor").html("交易密码填写错误，请重新填写");
                            $("#div_ErrorInfor").show();
                        }
                        else if (data == "-1") {
                            if (confirm("您的交易密码尚未注册,请去完善！")) {
                                window.location.href = "/MyInfo/PersonalInformation.aspx";
                            }
                        }
                    }
                });
            }
        }


        //检测短信验证码
        function CheckSMSCode() {
            var smscode = $("#txt_smscode").val();
            $.post("FinanceHandler.ashx?action=CheckCodeToWithdraw", { "smscode": smscode }, function (data, status) {
                if (data == "1") {
                    $("#div_ErrorInfor").hide();
                }
                else {
                    $("#div_ErrorInfor").html("短信验证码不正确或已过期");
                    $("#div_ErrorInfor").show();
                }
            });
        }

        function BankSelectChange(i) {
            var id = $(i).val();
            var newnumber = id.toString().substring(0, 6) + "***" + id.toString().substring(id.toString().length - 4, id.toString().length);
            $("#txt_BankCardId").val(newnumber);
        }

        function ChangeSXFShow(i) {
            var id = i.id;
            if (id == "RadioGroup1_0") {
                //普通到账
                $("#lbl_SXF1").show();
                $("#lbl_SXF2").hide();
            }
            else {
                //快速到账
                $("#lbl_SXF1").hide();
                $("#lbl_SXF2").show();
            }
            $("#true_money").hide();
            MoneyConpare();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:HiddenField ID="HiddenMoney" runat="server" />
        <!--content begin-->
        <div class="wrap jy-bg">
            <div class="trade-bt w1120 clearfix">
                <div class="trade-tit"><a href="javascript:;" class="cur">&nbsp;提&nbsp;现&nbsp;</a></div>
            </div>
        </div>
        <!---->
        <div class="add-con" style="padding-bottom: 50px;">
            <div class="balance">账户余额</div>
            <div class="balance-num">
                <em>
                    <asp:Literal ID="lbl_Money" runat="server"></asp:Literal></em>元<a href="TransactionRecords.aspx?type=1" class="blue left-bj">提现记录</a>
            </div>
            <div class="add-box" style="padding-left: 40px;">
                <ul>
                    <li>
                        <div class="xg-left">选择银行卡：</div>
                        <div class="xg-right">
                            <span>
                                <select name="" class="bankselect" onchange="BankSelectChange(this);">
                                </select>
                            </span><span class="addbank-link"><a href="AddBank.aspx" class="gray">添加银行卡</a>
                            </span>
                        </div>
                        <input id="txt_BankCardId" type="text" name="name" value="" readonly="true" style="padding-left: 20px; background-color: #eaeaea; font-size: 24px; color: #666; border: 1px solid #ccc; margin-left: 190px; height: 36px; width: 330px; border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;" />
                    </li>
                    <li>
                        <div class="xg-left">选择到账时间：</div>
                        <div class="xg-right">
                            <label>
                                <input type="radio" name="RadioGroup1" value="1" id="RadioGroup1_0" checked="checked" onchange="ChangeSXFShow(this);" />
                                1~5个工作日</label>
                            <label>
                                <input type="radio" name="RadioGroup1" value="2" id="RadioGroup1_1" onchange="ChangeSXFShow(this);" />
                                2小时到账</label>
                            <br />
                            <label id="lbl_SXF1" style="color:#FF0000; font-size:15px;">平台收取手续费5元</label>
                            <label id="lbl_SXF2" style="display:none; color:#FF0000; font-size:15px;">平台收取手续费10元</label>
                        </div>
                    </li>
                    <li>
                        <div class="xg-left"><span class="red">*</span>提现金额：</div>
                        <div class="xg-right">
                            <p>
                                <input id="txt_Money" type="text" class="add-input" onblur="MoneyConpare();" />&nbsp;&nbsp;元 <label id="true_money" style="color:red; font-size:16px; margin-left:20px;display:none;"></label>
                            </p>
                            <p class="r-tips1">单笔提现最高金额为50000元</p>
                        </div>
                    </li>
                    <li>
                        <div class="xg-left"><span class="red">*</span>交易密码：</div>
                        <div class="xg-right">
                            <p class="trade-passward">
                                <input id="txt_password" type="password" class="add-input" onblur="CheckTradePassword();" /><a href="javascript:;" class="pwdbtn"></a>
                            </p>
                            <p class="r-tips1">请输入交易密码</p>
                        </div>
                    </li>
                    <li>
                        <div class="xg-left"><span class="red">*</span>短信验证码：</div>
                        <div class="xg-right">
                            <p>
                                <span>
                                    <input id="txt_smscode" type="text" class="add-input" style="width: 140px;" onblur="CheckSMSCode();" />
                                </span><span><a href="javascript:;" class="yzm-click" onclick="SendSMSCode();">获取短信验证码</a><a href="javascript:;" class="yzm-notclick" style="display: none;">60s后重新获取</a></span>
                            </p>
                            <p class="r-tips1">请输入6位短信验证码</p>
                            <p id="div_ErrorInfor" class="r-tips2" style="display: none;">您输入的验证码有误</p>
                            <span id="span_code" style="display: none;"></span>
                        </div>
                    </li>
                    <li>
                        <div class="xg-left">&nbsp;</div>
                        <div class="xg-right">
                            <a id="btn_apply" href="javascript:;" onclick="" class="next-submit">提交申请</a>

                        </div>
                    </li>
                </ul>
            </div>
            <div class="notice-con">
                <p><strong>最新公告&nbsp;</strong>普通提现:1-5个工作日到账，周末、法定节假日及银行系统升级期间除外。</p>
                <p class="zbj1">快速提现:2小时到账提现申请时间：10:00-14:00。周末、法定节假日及银行系统升级期间除外；</p>
                <p class="zbj2">
                    若因为用户的原因（卡号不正确、姓名与卡号不匹配等）造成未到账，提现手续费将不<br />
                    2小时到账提现通道只支持储蓄卡；<br />
                    未开通实时到账的银行不可使用，建议使用工商、招商、建设、中国银行进行提现；<br />
                    可免费尊享到账短信通知。
                </p>
                <p>
                    温馨提示：提现申请后建议您及时关注提现银行卡的网银明细，以实际到账时间为准。<br />
                    如有咨询请拨打客服热线：400-153-6868。
                </p>
            </div>
        </div>
        <!--content end-->
    </form>
</body>
</html>
